package com.gtm.controller;

import com.gtm.model.Review;
import com.gtm.repository.ReviewRepository;
import com.gtm.repository.UserRepository;
import com.gtm.service.ReviewService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.text.ParseException;
import java.util.List;

@RestController
@RequestMapping("/review")
public class ReviewController {
    @Autowired
    ReviewRepository rvr;

    @Autowired
    ReviewService rvs;

    @Autowired
    UserRepository usr;

    @ApiOperation(value="uploadReview", notes="上传文献综述",httpMethod = "POST")
    @ApiImplicitParams(value ={
            @ApiImplicitParam(name = "sid",value = "学生id",dataType = "String",paramType = "path"),
            @ApiImplicitParam(name = "summary",value = "概要",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "keys",value = "关键词",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "references",value = "摘要",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "reviewFile",value = "文件",dataType = "MultipartFile",paramType = "query")
    } )
    @RequestMapping("/uploadReview/{sid}")
    public Review uploadReview(@PathVariable String sid,@RequestParam("summary")String summary,
                               @RequestParam("keys")String keys,@RequestParam("references")String references,
                               @RequestParam("reviewFile")MultipartFile reviewFile) throws ParseException, IOException {
        return rvs.uploadReview(sid,summary,keys,references,reviewFile);
    }

    @ApiOperation(value="listBySid", notes="通过学生查找综述",httpMethod = "POST")
    @ApiImplicitParams(value ={
            @ApiImplicitParam(name = "sid",value = "学生id",dataType = "String",paramType = "path")
    } )
    @RequestMapping("/listBySid/{sid}")
    public Review listBySid(@PathVariable String sid){
        return rvr.findByStuId(sid);
    }

    @ApiOperation(value="passReview", notes="通过综述",httpMethod = "POST")
    @ApiImplicitParams(value ={
            @ApiImplicitParam(name = "rid",value = "id",dataType = "String",paramType = "path"),
            @ApiImplicitParam(name = "comment",value = "评论",dataType = "String",paramType = "query")
    } )
    @RequestMapping("/passReview/{rid}")
    public Review passReview(@PathVariable String rid,@RequestParam("comment") String comment){
        return rvs.passReview(rid,comment);
    }

    @ApiOperation(value="depassReview", notes="撤销通过",httpMethod = "POST")
    @ApiImplicitParams(value ={
            @ApiImplicitParam(name = "rid",value = "id",dataType = "String",paramType = "path"),
            @ApiImplicitParam(name = "comment",value = "评论",dataType = "String",paramType = "query")
    } )
    @RequestMapping("/depassReview/{rid}")
    public Review depassReview(@PathVariable String rid,@RequestParam("comment") String comment){
        return rvs.depassReview(rid,comment);
    }

    @ApiOperation(value="listByTid", notes="列出对应课题的综述",httpMethod = "POST")
    @ApiImplicitParams(value ={
            @ApiImplicitParam(name = "tid",value = "topicid",dataType = "String",paramType = "path")
    } )
    @RequestMapping("/listByTid/{tid}")
    public Review listByTid(@PathVariable String tid){
        return rvs.listByTid(tid);
    }

    @ApiOperation(value="findById", notes="通过id查找",httpMethod = "POST")
    @ApiImplicitParams(value ={
            @ApiImplicitParam(name = "rid",value = "id",dataType = "String",paramType = "path")
    } )
    @RequestMapping("/findById/{rid}")
    public Review findById(@PathVariable String rid){
        System.out.println(rid);
        return rvr.findOne(rid);
    }


}
